package com.fansl.allround.common.core.util;

import com.fansl.allround.common.core.constant.CommonConstants;
import com.fansl.allround.common.core.constant.enums.ResultEnum;
import lombok.*;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * @author fansl
 * @Description: 响应信息主体
 * @date 2019/7/11 16:10
 */
@Builder
@ToString
@Accessors(chain = true)
@AllArgsConstructor
public class R<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    @Getter
    @Setter
    private int code = ResultEnum.SUCCESS.getCode();

    @Getter
    @Setter
    private String msg = ResultEnum.SUCCESS.getMessage();


    @Getter
    @Setter
    private T data;

    public R() {
        super();
    }

    public R(T data) {
        super();
        this.data = data;
    }

    public R(T data, String msg) {
        super();
        this.data = data;
        this.msg = msg;
    }

    public R(Throwable e) {
        super();
        this.msg = e.getMessage();
        this.code = ResultEnum.FAILED.getCode();
    }
    public R(ResultEnum resultEnum, T data) {
        super();
        this.msg = resultEnum.getMessage();
        this.code = resultEnum.getCode();
        this.data = data;
    }
}
